package nc.hw;

public class HJ20 {

    public static void main(String[] args) {
        System.out.println(checkIsCorrect("021Abc9000"));
        System.out.println(checkIsCorrect("021Abc9Abc1"));
        System.out.println(checkIsCorrect("021ABC9000"));
        System.out.println(checkIsCorrect("021$bc9000"));
    }

    private static String checkIsCorrect(String pwd) {
        if (pwd.length() <= 8) {
            return "NG";
        }
        int[] types = new int[4];
        for (char c : pwd.toCharArray()) {
            if (c >= '0' && c <= '9') {
                types[0] = 1;
            } else if (c >= 'a' && c <= 'z') {
                types[1] = 1;
            } else if (c >= 'A' && c <= 'Z') {
                types[2] = 1;
            } else {
                types[3] = 1;
            }
        }
        int typeCheck = 0;
        for (int i = 0; i < 4; i++) {
            typeCheck += types[i];
        }
        if (typeCheck < 3) {
            return "NG";
        }
        // 检测长度等于3的串重复
        for (int i = 0; i < pwd.length() - 3; i++) {
            String str = pwd.substring(i , i + 3);
            int i1 = pwd.lastIndexOf(str);
            if (i1 != i) {
                return "NG";
            }
        }
        return "OK";
    }

}
